<?php

namespace app\common\service\learn;

use app\common\model\banxi\learn\LearnTwentyAntiForgetting;
use app\common\model\banxi\learn\LearnTwentyAntiForgettingReview;
use app\common\model\banxi\student\Student;
use app\common\service\ApiService;
use app\common\service\course\LexiconService;

class LearnAntiForgettingService extends ApiService
{
    public function getReport($antiForgettingId, $reviewId, $reviewType)
    {
        $report = [];
        if ($reviewId) {
            $report = LearnTwentyAntiForgettingReview::with([
                'forgetWords' => function ($query) {
                    $query->where(['result' => 3]);
                }])->where('id', $reviewId)->find();
        }
        if ($antiForgettingId) {
            $LearnTwentyAntiForgettingReview = new LearnTwentyAntiForgettingReview();
            $report = $LearnTwentyAntiForgettingReview->getByAntiForgettingId($antiForgettingId, $reviewType);
        }
        if (!$report) {
            return $report;
        }

        if ($report['reviewType'] == 1) {
            $antiForgetting = LearnTwentyAntiForgetting::where(['id' => $report['antiAmnesiaId']])->find();
            $studentInfo = Student::where(['id' => $antiForgetting['studentId']])->field('id,name,avatar')->find();
            $report['studentInfo'] = $studentInfo;
        }
        $lexiconService = new LexiconService();
        $report['forgetWords'] = $lexiconService->wrapperLexiconBase($report['forgetWords']);
        return $report;
    }
}
